﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 招聘网站
{
    public partial class Form2 : Form
    {
        public static string a;
        public static string phonenumb;
        public static string mima;
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (radioButton1.Checked == true)
            {
                string SqlStr = "server=.;database=zhaopin;integrated security=SSPI";
                SqlConnection conn = new SqlConnection(SqlStr);
                conn.Open();
                string selectsql = "Select * from table_5 where phonenumb ='" + textBox1.Text + "'and mima = '" + textBox2.Text + "'";
                SqlCommand comm = new SqlCommand(selectsql, conn);
                comm.CommandType = CommandType.Text;
                SqlDataReader sdr;
                sdr = comm.ExecuteReader();
                if (textBox3.Text == label4.Text + label5.Text + label6.Text + label7.Text)
                {
                    if (sdr.Read())
                    {
                        Form9 f9 = new Form9();
                        f9.Show();
                        this.Hide();
                        return;
                    }

                    MessageBox.Show("用户名或密码不正确，不能进入系统", "非法用户");
                    conn.Close();
                    textBox1.Clear();
                    textBox2.Clear();
                    textBox3.Clear();
                    textBox1.Focus();

                    Random ran = new Random();
                    label4.Text = ran.Next(10).ToString();
                    label5.Text = ran.Next(10).ToString();
                    label6.Text = ran.Next(10).ToString();
                    label7.Text = ran.Next(10).ToString();
                }
                else
                    MessageBox.Show("验证码不正确，请重新输入", "验证", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox1.Focus();
                conn.Close();
            }
            else if(radioButton2.Checked==true) 
            {
                string SqlStr = "server=.;database=zhaopin;integrated security=SSPI";
                SqlConnection conn = new SqlConnection(SqlStr);
                conn.Open();
            string selectsql = "Select * from table_1 where phonenumb ='" + textBox1.Text + "'and mima = '" + textBox2.Text + "'";
            SqlCommand comm = new SqlCommand(selectsql, conn);
            comm.CommandType = CommandType.Text;
            SqlDataReader sdr;
            sdr = comm.ExecuteReader();
            if (textBox3.Text == label4.Text + label5.Text + label6.Text + label7.Text)
            {
                if (sdr.Read())
                {
                    phonenumb = sdr["phonenumb"].ToString();

                    a = textBox1.Text;
                    Form6 f6 = new Form6();
                    f6.Show();
                    this.Hide();
                    return;
                }

                MessageBox.Show("用户名或密码不正确，不能进入系统", "非法用户");
                conn.Close();
                textBox1.Clear();
                textBox2.Clear();
                textBox3.Clear();
                textBox1.Focus();

                Random ran = new Random();
                label4.Text = ran.Next(10).ToString();
                label5.Text = ran.Next(10).ToString();
                label6.Text = ran.Next(10).ToString();
                label7.Text = ran.Next(10).ToString();
            }
            else
                MessageBox.Show("验证码不正确，请重新输入", "验证", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox1.Focus();
            conn.Close();
            }
        }

        private void label6_Click(object sender, EventArgs e)
        {
        
        }

        private void label8_Click(object sender, EventArgs e)
        {
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            Random ran = new Random();
            label4.Text = ran.Next(10).ToString();
            label5.Text = ran.Next(10).ToString();
            label6.Text = ran.Next(10).ToString();
            label7.Text = ran.Next(10).ToString();
            
        }
        }
    }

